<!--
File Created: 2018-01-29 15:06
Author: xxq (you@you.you)
__________________________________________________
Last Modified: 2018-01-31 17:19:57
Modified By: xxq (you@you.you>)
__________________________________________________
Copyright - 2018 xnb, xnb
-->
<!--
File Created: 2018-01-19 16:41
Author: xxq (you@you.you)
__________________________________________________
Last Modified: 2018-01-19 17:23:25
Modified By: xxq (you@you.you>)
__________________________________________________
Copyright - 2018 xnb, xnb
-->
<!DOCTYPE html>
<html>
<meta charset="utf-8">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>demo</title>
<script src="https://cdn.bootcss.com/jquery/1.11.3/jquery.min.js"></script>
<link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://cdn.bootcss.com/bootstrap-table/1.11.1/bootstrap-table.min.css" rel="stylesheet">
<script src="https://cdn.bootcss.com/bootstrap-table/1.11.1/bootstrap-table.min.js"></script>

<script src="https://cdn.jsdelivr.net/npm/colresizable@1.6.0/colResizable-1.6.min.js"></script> <!-- 拖动调整列宽 -->
<script src="https://cdn.bootcss.com/bootstrap-table/1.11.1/extensions/resizable/bootstrap-table-resizable.min.js"></script>

<link href="https://cdn.bootcss.com/bootstrap-table/1.11.1/extensions/sticky-header/bootstrap-table-sticky-header.css" rel="stylesheet">
<script src="https://cdn.bootcss.com/bootstrap-table/1.11.1/extensions/sticky-header/bootstrap-table-sticky-header.min.js"></script>


<!—如果想使用中文版也可以引入以下语言包 -->
<script src="https://cdn.bootcss.com/bootstrap-table/1.11.1/locale/bootstrap-table-zh-CN.min.js"></script>
<style>
	th, td{text-align: center}
	.table>tbody>tr>td, .table>tbody>tr>th, .table>tfoot>tr>td, .table>tfoot>tr>th, .table>thead>tr>td, .table>thead>tr>th{vertical-align: middle}
</style>
</head>

<body>
<div class='container'>
<h1>鼠标拖动调节列的宽 / 固定表头 / 服务端分页</h1>
<table id="table"></table>


</div>
<script type="module">
	import { fetchData, requiredParams} from './public.js'
	
	$(function(){
		fetchData('user/login.do', {loginName:'18812345678', password: '123456' }, res => {
			/* 接口返回示例
				{
					code: 200,
					msg: "ok",
					sessionkey: "vvKLsfB4sa6X00mhUZBe"        
				} 
			*/
		})
	
		initTable()
		function initTable() {
			$('#table').bootstrapTable({
				resizable:true,
				stickyHeader: true,
				stickyHeaderOffsetY: '0px',
				pagination: true, // 分页
				// pageSize : 2, // 每页的数据条数, 默认10
				
				sidePagination: 'server', // 服务端分页
				responseHandler: function(res) { // 数据渲染到页面前，对数据的重新处理
					var data = []
					for(var i=0; i< 5; i++) {
						data.push(...res.data)
					}
					return {
						rows: data, // 数据
						total: data.length // res.recordsTotal // 总条数
					}
				},

				method : 'post',	// 向服务器请求方式
				contentType: "application/x-www-form-urlencoded", // post要用这种

				url: 'http://uadmin.51xnb.cn/channel/getChannelInfoPage.do',
				queryParams: requiredParams(), // 必须在函数中， return对象格式的参数
				
				columns: [
					{
						field: 'id',
						title: 'Item ID',
						formatter: function(val, row, index){
							return '<button class="btn" data-id="'+val+'">编辑</button><span>'+row.levelName+'</span>'
						} 
					}, {
						field: 'createUserName',
						title: 'Name'
					}, {
						field: 'createUserPhone',
						title: '手机号'
					}
				],
				// data: createData(30)
			});
		}

		function getParam() {
			const param = requiredParams()
			// param.time = 2018
			return param;
		}

	});
</script>
</body>
</html>